
<form name="Calculator" action="?page=calculator" method="POST"> 
Simple Calculator by Farnoosh Javadi and Shilpi Nayak : <br><br><br<br>
Type Expression in the box:<input type="text" name="number" size="10"/> <br>
<input type="submit" value="Calculate" size="12" /> <br>
<?php 
if(isset($_POST['number'])){ 

$test=$_POST['number'];
$test = preg_replace('/\s+/', '', $test);

$number = '(?:\d+(?:[,.]\d+)?)'; // What is a number
$operators = '[+\/*\-]'; // Allowed math operators
$r = '/^(('.$number.'|'.'\s*\((?1)+\)|\((?1)+\))(?:'.$operators.'(?2))?)+$/'; 
if (preg_match($r, $test))
{
    eval('$result = '.$test.';');
    print $result;
}
else
{
    Print " error";  
}

eval('$result = '.$_POST['number'].';');}
?>
</form> 